using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

public class DebugText : MonoBehaviour
{
	public static DebugText instance;

	public Text TXT_Debug;

	private List<string> list = new List<string>();

	private float removeTime;

	public CanvasScaler[] canvasScalerList;

	public InputField inputf;

	private void Awake()
	{
		if (instance != null)
		{
			Object.Destroy(base.gameObject);
		}
		else
		{
			instance = this;
			Object.DontDestroyOnLoad(base.gameObject);
		}
		SetScreen();
	}

	private void Update()
	{
		removeTime -= Time.unscaledDeltaTime;
		if (list.Count > 0 && removeTime <= 0f)
		{
			removeTime = 5f;
			list.RemoveAt(0);
			TXT_Debug.text = string.Empty;
			for (int i = 0; i < list.Count; i++)
			{
				Text tXT_Debug = TXT_Debug;
				tXT_Debug.text = tXT_Debug.text + list[i] + "\n";
			}
		}
	}

	public void Show(string txt)
	{
		removeTime = 10f;
		list.Add(txt);
		int num = list.Count - 20;
		if (num < 1)
		{
			num = 0;
		}
		for (int i = 0; i < num; i++)
		{
			list.RemoveAt(0);
		}
		TXT_Debug.text = string.Empty;
		for (int j = 0; j < list.Count; j++)
		{
			Text tXT_Debug = TXT_Debug;
			tXT_Debug.text = tXT_Debug.text + list[j] + "\n";
		}
	}

	private void SetScreen()
	{
		if ((float)Screen.height / (float)Screen.width > 0.57f)
		{
			for (int i = 0; i < canvasScalerList.Length; i++)
			{
				canvasScalerList[i].matchWidthOrHeight = 0f;
			}
		}
		else
		{
			for (int j = 0; j < canvasScalerList.Length; j++)
			{
				canvasScalerList[j].matchWidthOrHeight = 1f;
			}
		}
	}
}
